package com.cmcc.fj12580.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.Gallery;

import com.cmcc.fj12580.utils.Constant;

public class MGallery extends Gallery {

	public MGallery(Context context) {
		super(context);
	}

	public MGallery(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public MGallery(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}

	@Override
	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
		return false;
	}

	private int index;
	private int lenght;
	private float event_x;
	private boolean isMcount;

	public void setIndex(int index, int lenght) {
		this.index = index;
		this.lenght = lenght;
		isMcount = false;
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		switch (event.getAction()) {
		case MotionEvent.ACTION_DOWN:
			isMcount=false;
			Constant.isChildMove = true;
			event_x = event.getX();
			break;
		case MotionEvent.ACTION_MOVE:
			if (!isMcount) {
				if(lenght==0){
					isMcount=true;
					Constant.isChildMove = false;
				}else if ((index == 0 && event.getX() - event_x > 0) || (index == (lenght-1) && event.getX() - event_x < 0)) {
					isMcount=true;
					Constant.isChildMove = false;
				}
			}
			break;
		case MotionEvent.ACTION_UP:
			Constant.isChildMove = false;
			break;
		}
		return super.onTouchEvent(event);
	}
}
